﻿using Huirui.Cavan.Core.MyLinq;
using Huirui.Cavan.Core.Persistent;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Core.Extension;

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    public class SupplierTypeSpecification : ISpecification<SupplierType, SupplierTypeSearch>
    {
        #region ISpecification<SupplierType,SupplierTypeSearch> Members

        public SupplierTypeSearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<SupplierType> Members

        public System.Linq.Expressions.Expression<Func<SupplierType, bool>> Expression
        {
            get
            {
                IQueryBuilder<SupplierType> queryBuilder = QueryBuilder.Create<SupplierType>();

                if (SearchParams.IsNotNull())
                {
                    if (SearchParams.Name.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(s => s.Name, SearchParams.Name);
                    }
                }
                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
